
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 05/22/2011 00:38:14
-- Generated from EDMX file: C:\Programming\Work\Aidbrella\Aidbrella.Model\AidBrellaModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [AidBrella];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserProjectUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectUserSet] DROP CONSTRAINT [FK_UserProjectUser];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectUserProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectUserSet] DROP CONSTRAINT [FK_ProjectUserProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectUserUserProjectType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectUserSet] DROP CONSTRAINT [FK_ProjectUserUserProjectType];
GO
IF OBJECT_ID(N'[dbo].[FK_UserOrganizationFollowerUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationFollowerUserSet] DROP CONSTRAINT [FK_UserOrganizationFollowerUser];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationFollowerUserOrganization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationFollowerUserSet] DROP CONSTRAINT [FK_OrganizationFollowerUserOrganization];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationOrganizationLinkSource]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationLinkSet] DROP CONSTRAINT [FK_OrganizationOrganizationLinkSource];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationOrganizationLinkTarget]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationLinkSet] DROP CONSTRAINT [FK_OrganizationOrganizationLinkTarget];
GO
IF OBJECT_ID(N'[dbo].[FK_OraganizationLinkTypeOrganizationLink]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationLinkSet] DROP CONSTRAINT [FK_OraganizationLinkTypeOrganizationLink];
GO
IF OBJECT_ID(N'[dbo].[FK_UserOrganizationRoleUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationRoleUserSet] DROP CONSTRAINT [FK_UserOrganizationRoleUser];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationRoleUserTypeOrganizationRoleUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationRoleUserSet] DROP CONSTRAINT [FK_OrganizationRoleUserTypeOrganizationRoleUser];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectSiteProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectSiteSet] DROP CONSTRAINT [FK_ProjectSiteProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectLinkTypeProjectLink]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectLinkSet] DROP CONSTRAINT [FK_ProjectLinkTypeProjectLink];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectProjectLinkSource]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectLinkSet] DROP CONSTRAINT [FK_ProjectProjectLinkSource];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectProjectLinkTarget]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectLinkSet] DROP CONSTRAINT [FK_ProjectProjectLinkTarget];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectActivityProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectActivitySet] DROP CONSTRAINT [FK_ProjectActivityProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectResultProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectResultSet] DROP CONSTRAINT [FK_ProjectResultProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectObjectiveProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectObjectiveSet] DROP CONSTRAINT [FK_ProjectObjectiveProject];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationProjectOrganization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationProjectSet] DROP CONSTRAINT [FK_OrganizationProjectOrganization];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectOrganizationProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationProjectSet] DROP CONSTRAINT [FK_ProjectOrganizationProject];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationProjectOrganizationProjectType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationProjectSet] DROP CONSTRAINT [FK_OrganizationProjectOrganizationProjectType];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectProjectSector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectSet] DROP CONSTRAINT [FK_ProjectProjectSector];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectCommentUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectCommentSet] DROP CONSTRAINT [FK_ProjectCommentUser];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectCommentProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectCommentSet] DROP CONSTRAINT [FK_ProjectCommentProject];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationOrganizationType]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationSet] DROP CONSTRAINT [FK_OrganizationOrganizationType];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectImageProject]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectImageSet] DROP CONSTRAINT [FK_ProjectImageProject];
GO
IF OBJECT_ID(N'[dbo].[FK_ProjectImageUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProjectImageSet] DROP CONSTRAINT [FK_ProjectImageUser];
GO
IF OBJECT_ID(N'[dbo].[FK_OrganizationRoleUserOrganization]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[OrganizationRoleUserSet] DROP CONSTRAINT [FK_OrganizationRoleUserOrganization];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationSet];
GO
IF OBJECT_ID(N'[dbo].[UserProjectTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserProjectTypeSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectUserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectUserSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationFollowerUserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationFollowerUserSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationLinkSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationLinkSet];
GO
IF OBJECT_ID(N'[dbo].[OraganizationLinkTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OraganizationLinkTypeSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationRoleUserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationRoleUserSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationRoleUserTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationRoleUserTypeSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSiteSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSiteSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectLinkSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectLinkSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectLinkTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectLinkTypeSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectActivitySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectActivitySet];
GO
IF OBJECT_ID(N'[dbo].[ProjectResultSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectResultSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectObjectiveSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectObjectiveSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationProjectSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationProjectSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectSectorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectSectorSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationProjectTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationProjectTypeSet];
GO
IF OBJECT_ID(N'[dbo].[ProjectCommentSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectCommentSet];
GO
IF OBJECT_ID(N'[dbo].[OrganizationType]', 'U') IS NOT NULL
    DROP TABLE [dbo].[OrganizationType];
GO
IF OBJECT_ID(N'[dbo].[ProjectImageSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProjectImageSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [UserName] nvarchar(max)  NOT NULL,
    [Created] datetime  NOT NULL,
    [Modified] datetime  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL,
    [ImageUrl] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ProjectSet'
CREATE TABLE [dbo].[ProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NULL,
    [StartDate] datetime  NULL,
    [EndDate] datetime  NULL,
    [ProjectSectorId] int  NULL,
    [Email] nvarchar(max)  NULL,
    [WebSite] nvarchar(max)  NULL,
    [PhoneNumber] nvarchar(max)  NULL,
    [FullAddress] nvarchar(max)  NULL,
    [TotalBudget] nvarchar(max)  NULL,
    [BeneficiaryNumber] nvarchar(max)  NULL,
    [BeneficiaryDescription] nvarchar(max)  NULL,
    [ShortTermVolunteering] bit  NOT NULL,
    [LongTermVolunteering] bit  NOT NULL,
    [VolunteeringDescription] nvarchar(max)  NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationSet'
CREATE TABLE [dbo].[OrganizationSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Website] nvarchar(max)  NULL,
    [ContactEmail] nvarchar(max)  NULL,
    [ContactPhone] nvarchar(50)  NULL,
    [FullAddress] nvarchar(50)  NULL,
    [OrganizationTypeId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'UserProjectTypeSet'
CREATE TABLE [dbo].[UserProjectTypeSet] (
    [Id] tinyint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectUserSet'
CREATE TABLE [dbo].[ProjectUserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [ProjectId] int  NOT NULL,
    [UserProjectTypeId] tinyint  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationFollowerUserSet'
CREATE TABLE [dbo].[OrganizationFollowerUserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [OrganizationId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationLinkSet'
CREATE TABLE [dbo].[OrganizationLinkSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [SourceOrganizationId] int  NOT NULL,
    [TargetOrganizationId] int  NOT NULL,
    [OraganizationLinkTypeId] tinyint  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OraganizationLinkTypeSet'
CREATE TABLE [dbo].[OraganizationLinkTypeSet] (
    [Id] tinyint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationRoleUserSet'
CREATE TABLE [dbo].[OrganizationRoleUserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [UserId] int  NOT NULL,
    [OrganizationRoleUserTypeId] tinyint  NOT NULL,
    [Timestamp] timestamp  NOT NULL,
    [OrganizationId] int  NOT NULL
);
GO

-- Creating table 'OrganizationRoleUserTypeSet'
CREATE TABLE [dbo].[OrganizationRoleUserTypeSet] (
    [Id] tinyint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectSiteSet'
CREATE TABLE [dbo].[ProjectSiteSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ProjectId] int  NOT NULL,
    [Latitude] float  NOT NULL,
    [Longitude] float  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectLinkSet'
CREATE TABLE [dbo].[ProjectLinkSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [ProjectLinkTypeId] tinyint  NOT NULL,
    [SourceProjectId] int  NOT NULL,
    [TargetProjectId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectLinkTypeSet'
CREATE TABLE [dbo].[ProjectLinkTypeSet] (
    [Id] tinyint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectActivitySet'
CREATE TABLE [dbo].[ProjectActivitySet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectResultSet'
CREATE TABLE [dbo].[ProjectResultSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectObjectiveSet'
CREATE TABLE [dbo].[ProjectObjectiveSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationProjectSet'
CREATE TABLE [dbo].[OrganizationProjectSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [OrganizationId] int  NOT NULL,
    [ProjectId] int  NOT NULL,
    [OrganizationProjectTypeId] tinyint  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectSectorSet'
CREATE TABLE [dbo].[ProjectSectorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationProjectTypeSet'
CREATE TABLE [dbo].[OrganizationProjectTypeSet] (
    [Id] tinyint IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectCommentSet'
CREATE TABLE [dbo].[ProjectCommentSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Comment] nvarchar(max)  NOT NULL,
    [CommentDate] datetime  NOT NULL,
    [UserId] int  NOT NULL,
    [ProjectId] int  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'OrganizationType'
CREATE TABLE [dbo].[OrganizationType] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(50)  NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- Creating table 'ProjectImageSet'
CREATE TABLE [dbo].[ProjectImageSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Url] nvarchar(max)  NOT NULL,
    [ProjectId] int  NOT NULL,
    [UserId] int  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Timestamp] timestamp  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [PK_ProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationSet'
ALTER TABLE [dbo].[OrganizationSet]
ADD CONSTRAINT [PK_OrganizationSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserProjectTypeSet'
ALTER TABLE [dbo].[UserProjectTypeSet]
ADD CONSTRAINT [PK_UserProjectTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectUserSet'
ALTER TABLE [dbo].[ProjectUserSet]
ADD CONSTRAINT [PK_ProjectUserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationFollowerUserSet'
ALTER TABLE [dbo].[OrganizationFollowerUserSet]
ADD CONSTRAINT [PK_OrganizationFollowerUserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationLinkSet'
ALTER TABLE [dbo].[OrganizationLinkSet]
ADD CONSTRAINT [PK_OrganizationLinkSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OraganizationLinkTypeSet'
ALTER TABLE [dbo].[OraganizationLinkTypeSet]
ADD CONSTRAINT [PK_OraganizationLinkTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationRoleUserSet'
ALTER TABLE [dbo].[OrganizationRoleUserSet]
ADD CONSTRAINT [PK_OrganizationRoleUserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationRoleUserTypeSet'
ALTER TABLE [dbo].[OrganizationRoleUserTypeSet]
ADD CONSTRAINT [PK_OrganizationRoleUserTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSiteSet'
ALTER TABLE [dbo].[ProjectSiteSet]
ADD CONSTRAINT [PK_ProjectSiteSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectLinkSet'
ALTER TABLE [dbo].[ProjectLinkSet]
ADD CONSTRAINT [PK_ProjectLinkSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectLinkTypeSet'
ALTER TABLE [dbo].[ProjectLinkTypeSet]
ADD CONSTRAINT [PK_ProjectLinkTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectActivitySet'
ALTER TABLE [dbo].[ProjectActivitySet]
ADD CONSTRAINT [PK_ProjectActivitySet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectResultSet'
ALTER TABLE [dbo].[ProjectResultSet]
ADD CONSTRAINT [PK_ProjectResultSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectObjectiveSet'
ALTER TABLE [dbo].[ProjectObjectiveSet]
ADD CONSTRAINT [PK_ProjectObjectiveSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationProjectSet'
ALTER TABLE [dbo].[OrganizationProjectSet]
ADD CONSTRAINT [PK_OrganizationProjectSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectSectorSet'
ALTER TABLE [dbo].[ProjectSectorSet]
ADD CONSTRAINT [PK_ProjectSectorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'OrganizationProjectTypeSet'
ALTER TABLE [dbo].[OrganizationProjectTypeSet]
ADD CONSTRAINT [PK_OrganizationProjectTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectCommentSet'
ALTER TABLE [dbo].[ProjectCommentSet]
ADD CONSTRAINT [PK_ProjectCommentSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [ID] in table 'OrganizationType'
ALTER TABLE [dbo].[OrganizationType]
ADD CONSTRAINT [PK_OrganizationType]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [Id] in table 'ProjectImageSet'
ALTER TABLE [dbo].[ProjectImageSet]
ADD CONSTRAINT [PK_ProjectImageSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserId] in table 'ProjectUserSet'
ALTER TABLE [dbo].[ProjectUserSet]
ADD CONSTRAINT [FK_UserProjectUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProjectUser'
CREATE INDEX [IX_FK_UserProjectUser]
ON [dbo].[ProjectUserSet]
    ([UserId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectUserSet'
ALTER TABLE [dbo].[ProjectUserSet]
ADD CONSTRAINT [FK_ProjectUserProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectUserProject'
CREATE INDEX [IX_FK_ProjectUserProject]
ON [dbo].[ProjectUserSet]
    ([ProjectId]);
GO

-- Creating foreign key on [UserProjectTypeId] in table 'ProjectUserSet'
ALTER TABLE [dbo].[ProjectUserSet]
ADD CONSTRAINT [FK_ProjectUserUserProjectType]
    FOREIGN KEY ([UserProjectTypeId])
    REFERENCES [dbo].[UserProjectTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectUserUserProjectType'
CREATE INDEX [IX_FK_ProjectUserUserProjectType]
ON [dbo].[ProjectUserSet]
    ([UserProjectTypeId]);
GO

-- Creating foreign key on [UserId] in table 'OrganizationFollowerUserSet'
ALTER TABLE [dbo].[OrganizationFollowerUserSet]
ADD CONSTRAINT [FK_UserOrganizationFollowerUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserOrganizationFollowerUser'
CREATE INDEX [IX_FK_UserOrganizationFollowerUser]
ON [dbo].[OrganizationFollowerUserSet]
    ([UserId]);
GO

-- Creating foreign key on [OrganizationId] in table 'OrganizationFollowerUserSet'
ALTER TABLE [dbo].[OrganizationFollowerUserSet]
ADD CONSTRAINT [FK_OrganizationFollowerUserOrganization]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[OrganizationSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationFollowerUserOrganization'
CREATE INDEX [IX_FK_OrganizationFollowerUserOrganization]
ON [dbo].[OrganizationFollowerUserSet]
    ([OrganizationId]);
GO

-- Creating foreign key on [SourceOrganizationId] in table 'OrganizationLinkSet'
ALTER TABLE [dbo].[OrganizationLinkSet]
ADD CONSTRAINT [FK_OrganizationOrganizationLinkSource]
    FOREIGN KEY ([SourceOrganizationId])
    REFERENCES [dbo].[OrganizationSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationOrganizationLinkSource'
CREATE INDEX [IX_FK_OrganizationOrganizationLinkSource]
ON [dbo].[OrganizationLinkSet]
    ([SourceOrganizationId]);
GO

-- Creating foreign key on [TargetOrganizationId] in table 'OrganizationLinkSet'
ALTER TABLE [dbo].[OrganizationLinkSet]
ADD CONSTRAINT [FK_OrganizationOrganizationLinkTarget]
    FOREIGN KEY ([TargetOrganizationId])
    REFERENCES [dbo].[OrganizationSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationOrganizationLinkTarget'
CREATE INDEX [IX_FK_OrganizationOrganizationLinkTarget]
ON [dbo].[OrganizationLinkSet]
    ([TargetOrganizationId]);
GO

-- Creating foreign key on [OraganizationLinkTypeId] in table 'OrganizationLinkSet'
ALTER TABLE [dbo].[OrganizationLinkSet]
ADD CONSTRAINT [FK_OraganizationLinkTypeOrganizationLink]
    FOREIGN KEY ([OraganizationLinkTypeId])
    REFERENCES [dbo].[OraganizationLinkTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OraganizationLinkTypeOrganizationLink'
CREATE INDEX [IX_FK_OraganizationLinkTypeOrganizationLink]
ON [dbo].[OrganizationLinkSet]
    ([OraganizationLinkTypeId]);
GO

-- Creating foreign key on [UserId] in table 'OrganizationRoleUserSet'
ALTER TABLE [dbo].[OrganizationRoleUserSet]
ADD CONSTRAINT [FK_UserOrganizationRoleUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserOrganizationRoleUser'
CREATE INDEX [IX_FK_UserOrganizationRoleUser]
ON [dbo].[OrganizationRoleUserSet]
    ([UserId]);
GO

-- Creating foreign key on [OrganizationRoleUserTypeId] in table 'OrganizationRoleUserSet'
ALTER TABLE [dbo].[OrganizationRoleUserSet]
ADD CONSTRAINT [FK_OrganizationRoleUserTypeOrganizationRoleUser]
    FOREIGN KEY ([OrganizationRoleUserTypeId])
    REFERENCES [dbo].[OrganizationRoleUserTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationRoleUserTypeOrganizationRoleUser'
CREATE INDEX [IX_FK_OrganizationRoleUserTypeOrganizationRoleUser]
ON [dbo].[OrganizationRoleUserSet]
    ([OrganizationRoleUserTypeId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectSiteSet'
ALTER TABLE [dbo].[ProjectSiteSet]
ADD CONSTRAINT [FK_ProjectSiteProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectSiteProject'
CREATE INDEX [IX_FK_ProjectSiteProject]
ON [dbo].[ProjectSiteSet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectLinkTypeId] in table 'ProjectLinkSet'
ALTER TABLE [dbo].[ProjectLinkSet]
ADD CONSTRAINT [FK_ProjectLinkTypeProjectLink]
    FOREIGN KEY ([ProjectLinkTypeId])
    REFERENCES [dbo].[ProjectLinkTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectLinkTypeProjectLink'
CREATE INDEX [IX_FK_ProjectLinkTypeProjectLink]
ON [dbo].[ProjectLinkSet]
    ([ProjectLinkTypeId]);
GO

-- Creating foreign key on [SourceProjectId] in table 'ProjectLinkSet'
ALTER TABLE [dbo].[ProjectLinkSet]
ADD CONSTRAINT [FK_ProjectProjectLinkSource]
    FOREIGN KEY ([SourceProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectProjectLinkSource'
CREATE INDEX [IX_FK_ProjectProjectLinkSource]
ON [dbo].[ProjectLinkSet]
    ([SourceProjectId]);
GO

-- Creating foreign key on [TargetProjectId] in table 'ProjectLinkSet'
ALTER TABLE [dbo].[ProjectLinkSet]
ADD CONSTRAINT [FK_ProjectProjectLinkTarget]
    FOREIGN KEY ([TargetProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectProjectLinkTarget'
CREATE INDEX [IX_FK_ProjectProjectLinkTarget]
ON [dbo].[ProjectLinkSet]
    ([TargetProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectActivitySet'
ALTER TABLE [dbo].[ProjectActivitySet]
ADD CONSTRAINT [FK_ProjectActivityProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectActivityProject'
CREATE INDEX [IX_FK_ProjectActivityProject]
ON [dbo].[ProjectActivitySet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectResultSet'
ALTER TABLE [dbo].[ProjectResultSet]
ADD CONSTRAINT [FK_ProjectResultProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectResultProject'
CREATE INDEX [IX_FK_ProjectResultProject]
ON [dbo].[ProjectResultSet]
    ([ProjectId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectObjectiveSet'
ALTER TABLE [dbo].[ProjectObjectiveSet]
ADD CONSTRAINT [FK_ProjectObjectiveProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectObjectiveProject'
CREATE INDEX [IX_FK_ProjectObjectiveProject]
ON [dbo].[ProjectObjectiveSet]
    ([ProjectId]);
GO

-- Creating foreign key on [OrganizationId] in table 'OrganizationProjectSet'
ALTER TABLE [dbo].[OrganizationProjectSet]
ADD CONSTRAINT [FK_OrganizationProjectOrganization]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[OrganizationSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationProjectOrganization'
CREATE INDEX [IX_FK_OrganizationProjectOrganization]
ON [dbo].[OrganizationProjectSet]
    ([OrganizationId]);
GO

-- Creating foreign key on [ProjectId] in table 'OrganizationProjectSet'
ALTER TABLE [dbo].[OrganizationProjectSet]
ADD CONSTRAINT [FK_ProjectOrganizationProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectOrganizationProject'
CREATE INDEX [IX_FK_ProjectOrganizationProject]
ON [dbo].[OrganizationProjectSet]
    ([ProjectId]);
GO

-- Creating foreign key on [OrganizationProjectTypeId] in table 'OrganizationProjectSet'
ALTER TABLE [dbo].[OrganizationProjectSet]
ADD CONSTRAINT [FK_OrganizationProjectOrganizationProjectType]
    FOREIGN KEY ([OrganizationProjectTypeId])
    REFERENCES [dbo].[OrganizationProjectTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationProjectOrganizationProjectType'
CREATE INDEX [IX_FK_OrganizationProjectOrganizationProjectType]
ON [dbo].[OrganizationProjectSet]
    ([OrganizationProjectTypeId]);
GO

-- Creating foreign key on [ProjectSectorId] in table 'ProjectSet'
ALTER TABLE [dbo].[ProjectSet]
ADD CONSTRAINT [FK_ProjectProjectSector]
    FOREIGN KEY ([ProjectSectorId])
    REFERENCES [dbo].[ProjectSectorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectProjectSector'
CREATE INDEX [IX_FK_ProjectProjectSector]
ON [dbo].[ProjectSet]
    ([ProjectSectorId]);
GO

-- Creating foreign key on [UserId] in table 'ProjectCommentSet'
ALTER TABLE [dbo].[ProjectCommentSet]
ADD CONSTRAINT [FK_ProjectCommentUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectCommentUser'
CREATE INDEX [IX_FK_ProjectCommentUser]
ON [dbo].[ProjectCommentSet]
    ([UserId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectCommentSet'
ALTER TABLE [dbo].[ProjectCommentSet]
ADD CONSTRAINT [FK_ProjectCommentProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectCommentProject'
CREATE INDEX [IX_FK_ProjectCommentProject]
ON [dbo].[ProjectCommentSet]
    ([ProjectId]);
GO

-- Creating foreign key on [OrganizationTypeId] in table 'OrganizationSet'
ALTER TABLE [dbo].[OrganizationSet]
ADD CONSTRAINT [FK_OrganizationOrganizationType]
    FOREIGN KEY ([OrganizationTypeId])
    REFERENCES [dbo].[OrganizationType]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationOrganizationType'
CREATE INDEX [IX_FK_OrganizationOrganizationType]
ON [dbo].[OrganizationSet]
    ([OrganizationTypeId]);
GO

-- Creating foreign key on [ProjectId] in table 'ProjectImageSet'
ALTER TABLE [dbo].[ProjectImageSet]
ADD CONSTRAINT [FK_ProjectImageProject]
    FOREIGN KEY ([ProjectId])
    REFERENCES [dbo].[ProjectSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectImageProject'
CREATE INDEX [IX_FK_ProjectImageProject]
ON [dbo].[ProjectImageSet]
    ([ProjectId]);
GO

-- Creating foreign key on [UserId] in table 'ProjectImageSet'
ALTER TABLE [dbo].[ProjectImageSet]
ADD CONSTRAINT [FK_ProjectImageUser]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ProjectImageUser'
CREATE INDEX [IX_FK_ProjectImageUser]
ON [dbo].[ProjectImageSet]
    ([UserId]);
GO

-- Creating foreign key on [OrganizationId] in table 'OrganizationRoleUserSet'
ALTER TABLE [dbo].[OrganizationRoleUserSet]
ADD CONSTRAINT [FK_OrganizationRoleUserOrganization]
    FOREIGN KEY ([OrganizationId])
    REFERENCES [dbo].[OrganizationSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_OrganizationRoleUserOrganization'
CREATE INDEX [IX_FK_OrganizationRoleUserOrganization]
ON [dbo].[OrganizationRoleUserSet]
    ([OrganizationId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------